package heven.holt.eyepetizer.binding

import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import heven.holt.eyepetizer.R
import heven.holt.eyepetizer.adapter.SpecialSquareCardCollectionAdapter
import heven.holt.eyepetizer.model.ItemX
import heven.holt.library.extensions.conversionVideoDuration
import heven.holt.library.widget.driver.RecycleViewDivider

@BindingAdapter("android:bindSpecialSquareCardAdapter")
fun bindSpecialSquareCardAdapter(recyclerView: RecyclerView, itemList: List<ItemX>?) {
    recyclerView.layoutManager = GridLayoutManager(recyclerView.context, 2).apply {
        orientation = GridLayoutManager.HORIZONTAL
    }
    if (recyclerView.itemDecorationCount == 0) {
        recyclerView.addItemDecoration(
            RecycleViewDivider(
                recyclerView.context,
                R.drawable.decoration_recycle_view
            )
        )
    }
    recyclerView.adapter = SpecialSquareCardCollectionAdapter(itemList ?: emptyList())
}

@BindingAdapter("android:bindVideoDuration")
fun bindVideoDuration(textView: TextView, duration: Int) {
    textView.text = duration.conversionVideoDuration()
}